// 实现所有分类数据相关操作
var conn = require('../utils/myconn')
//获取所有分类数据

exports.getAllCate = (callback)=>{
    var sql = 'select * from categories'
    conn.query(sql,(err,data)=>{
        if(err){
            callback(err)
        }else{
            callback(null,data)
        }
    })
}
//修改的
exports.categoriesById = (obj,callback)=>{
    var sql = `update categories set ? where id = ?`
    conn.query(sql,[{'slug': obj.slug, 'name': obj.name},obj.id],(err)=>{
        if(err){
            callback(err)
        }else{
            callback(null)
        }
    })
}

exports.categoriesAdd = (obj,callback)=>{
    var sql = `insert into categories set ?`
    conn.query(sql,obj,(err)=>{
        if(err){
            callback(err)
        }else{
            callback(null)
        }
    })
}

exports.cateDelById = (id,callback)=>{
    var sql = `DELETE FROM categories WHERE id = ?`
    conn.query(sql,[id],(err)=>{
        if(err){
            callback(err)
        }else{
            callback(null)
        }
    })
}

exports.delCateById = (ids,callback)=>{
    var sql = `DELETE FROM categories WHERE id in (${ids})`
    conn.query(sql,(err)=>{
        console.log(sql)
        if(err){
            callback(err)
        }else{
            callback(null)
        }
    })
}